#include "key.h"
#include "led.h"


struct keys key[4]={0};

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if(htim->Instance==TIM3)
	{
		key[0].key_sta=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0);
		key[1].key_sta=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1);
		key[2].key_sta=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2);
		key[3].key_sta=HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0);
		
		for(int i=0;i<4;i++)
		{
			switch(key[i].judge_sta)
			{
				case 0:
				{
					if(key[i].key_sta==0) key[i].judge_sta=1;
				}
				break;
				case 1:
				{
					if(key[i].key_sta==0) 
					{
						key[i].judge_sta=2;
						
					}
					else
						key[i].judge_sta=0;
				}
				break;
				case 2:
				{
					if(key[i].key_sta==1)
					{
						
						key[i].judge_sta=0;
						key[i].single_flag=1;
					}
					
				}
				break;
			}
			
		}
		
	}
}


MYKEY KEY_getb1()
{
	MYKEY key_value = ZERO;
	if(key[0].single_flag== 1)
	{
		key_value = PASS_1 ;
		key[0].single_flag=0;
	}
		if(key[1].single_flag== 1)
	{
		key_value = PASS_2 ;
		key[1].single_flag=0;
	}
		if(key[2].single_flag== 1)
	{
		key_value = PASS_3 ;
		key[2].single_flag=0;
	}
		if(key[3].single_flag== 1)
	{
		key_value = VERIFY ;
		key[3].single_flag=0;
	}
	
	return key_value ;
}
